package service.group;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.util.ArrayList;
import java.util.List;
import object.UserInfo;

import service.CommonServlet;

public class GetGroupUsers extends CommonServlet {
	
	@Override
	protected void execute(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		try
		{
			int gNo = Integer.parseInt( request.getParameter("gNo") );
			String sql = "select user.u_no,user.u_name from user,friend where friend.g_no= ? and friend.u_noz=user.u_no  and friend.u_noy= ?";
			PreparedStatement pstmt = mConnection.prepareStatement(sql);
			pstmt.setInt(1, gNo);
			pstmt.setInt(2, uNo);
			ResultSet rs = pstmt.executeQuery();
			List<UserInfo> userinfos = new ArrayList<UserInfo>();
			while(rs.next())
			{
				UserInfo userinfo = new UserInfo();
				userinfo.setuNo( rs.getInt("user.u_no") );
				userinfo.setuName( rs.getString("user.u_name") );
				userinfos.add(userinfo);
			}
			sendObject(userinfos, response);
		}
		catch (Exception e)
		{
			e.printStackTrace();
		}
	}

	/**
	 * Constructor of the object.
	 */
	public GetGroupUsers() {
		super();
	}

}
